/*
 * Dfunc.cpp
 *
 *  Created on: Nov 9, 2011
 *      Author: yi
 */

#include "mbuild/Dfunc.h"
const double Dfunc::Inf=1e298;
Dfunc::Dfunc() {
	/*
	 * A constructor for abstract class make no sense, just remind what should be the default.
	 */
	IsAdditive=false;
	mode=SOLUTE_GT;
}

Dfunc::~Dfunc() {
}

void Dfunc::set_additive(void)
{
	IsAdditive=true;
}

void Dfunc::unset_additive(void)
{
	IsAdditive=false;
}


inline double Dfunc::distance(double x, double y, double z)
{
	return((a*x+b*y+c*z+d)/e);
}

void Dfunc::set_plane(double a, double b, double c, double d)
{
	this->a=a;
	this->b=b;
	this->c=c;
	this->d=d;
	this->e=sqrt(a*a+b*b+c*c);
}

double Dfunc::operator ()(double d)
{
	return f(d);
}

inline double Dfunc::f(double x, double y, double z)
{
	return f(distance(x,y,z));
}


bool Dfunc::IfEqualSolute(double v)
{
	/*
	 * Skip the grid if the grid has already solute value.
	 * Default is false always.
	 * TODO Improve: put it into each child class as Dfunc is just a socket to interface with Membrane?
	 */
	switch (mode) {
		case SOLUTE_EQL : {
			if (v == solute_value) return true;
			else return false;
		}
		case SOLUTE_LT : {
			if (v < solute_value) return true;
			else return false;
		}
		case SOLUTE_GT : {
			if (v > solute_value) return true;
			else return false;
		}
		case SOLUTE_NEQL : {
			if (v != solute_value) return true;
			else return false;
		}
		case DONOTHING : {
			return false;
		}
	}
	  return false;
}

void Dfunc::Solute_Do_Not_Eql(double v)
{
	mode=SOLUTE_NEQL;
	solute_value=v;
}

void Dfunc::Solute_Eql(double v)
{
	mode=SOLUTE_EQL;
	solute_value=v;
}

void Dfunc::Solute_Less_Than(double v)
{
	mode=SOLUTE_LT;
	solute_value=v;
}

void Dfunc::Solute_Greater_Than(double v)
{
	mode=SOLUTE_GT;
	solute_value=v;
}





